<?php
namespace App\Services\util;
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/12/9
 * Time: 11:20
 */
use  Illuminate\Support\Facades\Redis;

class RedisUtil{
    
    public static function set($key,$val,$life_time = 0){
        if($life_time){
            Redis::setex($key,$life_time,$val);
        }else{
            Redis::set($key,$val);
        }
    }

//    public static function get($key){
//        return Redis::get($key);
//    }


    /**
     * 构造函数，避免重复构造redis的所有方法
     *
     * @param string $name
     * @param type $value
     */
    public static function __callStatic($name, $arguments){
        if($arguments){
            $key = $arguments[0];
            $arguments[0] = $key;
        }else{
            $arguments = array();
        }

        $len = count($arguments);
        switch($len){
            case 0:{
                $return = Redis::$name();
                break;
            }
            case 1:{
                $return = Redis::$name($arguments[0]);
                break;
            }
            case 2:{
                $return = Redis::$name($arguments[0], $arguments[1]);
                break;
            }
            case 3:{
                $return = Redis::$name($arguments[0], $arguments[1], $arguments[2]);
                break;
            }
        }
        return $return;
    }

}